package UILayer;
import java.util.Scanner;
import CtrlLayer.*;
import ModelLayer.Customer;

public class CustomerUI
{
	private PersonCtrl PC;
	private Customer mycustomer;
	
    public CustomerUI()
    {
    	PC = new PersonCtrl();
    }
    
    public void CustomerMenu()
    {   
    	boolean exit = false;
        while (!exit) //! means while exit not is true (that is: false)
        {
        	int choise = writeCustomerMenu();
        	switch(choise)
        	{
        		case 1: addCustumer(); break;
        		case 2: delCustumer(); break;
        		case 3: getCustomer(); break;
        		case 4: listAllCustomer(); break;
        		case 99: exit = true; break;
        	}//end switch
        }//end while
    }
    
    private int writeCustomerMenu()
    {
        //creates an object keyboard to read data from the keyboard
    	Scanner keyboard = new Scanner(System.in);
    	System.out.println(" *** Kunde Menu ***");
    	System.out.println(" (1) Opret Kunde");
    	System.out.println(" (2) Slet Kunde");
    	System.out.println(" (3) Find Kunde");
    	System.out.println(" (4) List alle Kunder");
    	System.out.println(" (99) Tilbage");
    	System.out.print("\n Make your choise: ");
    	int choise = keyboard.nextInt();
    	return choise;
    }
    
    public void addCustumer()
    {
    	String name = inputtext("Navn ");
    	String address = inputtext("Adresse ");
    	String postal = inputtext("Postnr ");
    	String city = inputtext("By ");
    	String phone = inputtext("Tlf ");
    	String email = inputtext("email ");
    	int craftsmanDiscount = inputintnumber("Haandvaerker rabat % ");
    	PC.createCustomer(name, address, postal, city, phone, email, craftsmanDiscount);
    }
    
    public void delCustumer()
    {
    	
    }
    
    public void getCustomer()
    {
    	String phone = inputtext("Tlf ");
    	mycustomer = PC.searchCustomer(phone);
    	System.out.println( mycustomer.getName() );
    	System.out.println( mycustomer.getAddress() );
    	System.out.println( mycustomer.getPostal() + "  " + mycustomer.getCity() );
    	System.out.println( "tlf: " + mycustomer.getPhone() );
    	System.out.println( mycustomer.getEmail() );
    	System.out.println( mycustomer.getCraftsmanDiscount() );
    }
    
    public void listAllCustomer()
    {
    	
    }
    
    /**
     * Print a text and takes input from keyboard
     * @param text Print text
     * @return str Return the input from the keyboard 
     */
    private String inputtext(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        return str;
    }
    
    private int inputintnumber(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        int no = Integer.parseInt(str.trim());  // convert String 2 long
        return no;
    }

}